package spring.demo13.notuse;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.ActiveMQConnectionFactory;

public class MessageConsumersMain {
	public static void main(String[] args) throws JMSException {
		ConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
		// 创建连接
		Connection cont = connectionFactory.createConnection();
		// 开始接收
		cont.start();
		Session session = cont.createSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);
		// 创建 一个 队列
		Queue queue = session.createQueue("notues_spring");
		// 创建生产者 consumers
		MessageConsumer messCon = session.createConsumer(queue);
		
		while (true) {
			TextMessage mess = (TextMessage) messCon.receive();
			// 如果 这时 中间键 没有队列时  这里就会等待
			if (mess == null)
				break;
			session.commit();
			String text = mess.getText();
			if (text == null || "".equals(text))
				break;
			System.out.println(text);
			
		}
		session.close();
		cont.close();
	}
}
